from .base import Sort


class Insertion(Sort):
    '''插入排序'''

    def name(self):
        return "插入排序"

    def sort(self, data, low=0, hight=None):
        hight = len(data) if hight is None else hight
        self.compare_counter = 0
        for i in range(low, hight):
            temp = data[i]
            target = i
            for j in range(i, low, -1):
                self.compare_counter += 1
                if self.compare(temp, data[j-1]):
                    data[j] = data[j-1]
                    target = j-1
                else:
                    break
            data[target] = temp
